package com.kim.authorization.server.controller;

import com.kim.authorization.server.config.util.AuthProperties;
import org.springframework.security.oauth2.provider.AuthorizationRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import java.util.Map;

/**
 * 自定义授权Controller
 */
@Controller
@SessionAttributes("authorizationRequest")
public class GrantController {

    /**
     * 自定义授权页面
     *
     * @param param 认证参数应该都在这里
     * @param model model
     * @return java.lang.String
     */
    @RequestMapping(AuthProperties.CONFIRM_ACCESS)
    public String getAccessConfirmation(Map<String, Object> param, Model model) {

        AuthorizationRequest authorizationRequest = (AuthorizationRequest) param.get("authorizationRequest");
        if (authorizationRequest == null) {
            return "redirect:" + AuthProperties.LOGIN_PAGE;
        }
        model.addAttribute("scopes", authorizationRequest.getScope());
        model.addAttribute("clientId", authorizationRequest.getClientId());
        return "grant";
    }

}
